<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="城市" prop="cityname">
        <el-input
          v-model="queryParams.cityname"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="spname">
        <el-input
          v-model="queryParams.spname"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业" prop="enname">
        <el-input
          v-model="queryParams.enname"
          placeholder="请输入企业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="sname">
        <el-input
          v-model="queryParams.sname"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['studentemployment:studentemployment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['studentemployment:studentemployment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['studentemployment:studentemployment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['studentemployment:studentemployment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentemploymentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学生ID" align="center" prop="sid" />
      <el-table-column label="城市" align="center" prop="cityname" />
      <el-table-column label="省份" align="center" prop="proname" />
      <el-table-column label="学院" align="center" prop="coname" />
      <el-table-column label="专业" align="center" prop="spname" />
      <el-table-column label="企业" align="center" prop="enname" />
      <el-table-column label="姓名" align="center" prop="sname" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="电话" align="center" prop="tel" />

      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="籍贯" align="center" prop="nativeplace" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="出生日期" align="center" prop="birthday" />
      <el-table-column label="入学时间" align="center" prop="intime" />
      <el-table-column label="毕业时间" align="center" prop="outtime" />
      <el-table-column label="就业时间" align="center" prop="etime" />
      <el-table-column label="就业薪资" align="center" prop="money" />
      <el-table-column label="状态" align="center" prop="stat" >
        <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.stat == 0">已就业</el-tag>
            <el-tag type="danger" v-if="scope.row.stat != 0">未就业</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['studentemployment:studentemployment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['studentemployment:studentemployment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改就业管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="省份" prop="proid">
              <el-select v-model="form.proid" @change="getProvinceCity" clearable placeholder="请选择">
                <el-option
                  v-for="item in provincesOption"
                  :key="item.proid"
                  :label="item.proname"
                  :value="item.proid">
                </el-option>
              </el-select>
            </el-form-item>
          </div></el-col>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="城市" prop="cityid">
              <el-select v-model="form.cityid" >
                <el-option
                  v-for="item in citysOption"
                  :key="item.cityid"
                  :label="item.cityname"
                  :value="item.cityid"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          </el-col>

        </el-row>


        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="学院" prop="coid">
              <el-select v-model="form.coid"  @change="getCollegeAllSpeciality">
                <el-option
                  v-for="item in collegesOption"
                  :key="item.coid"
                  :label="item.coname"
                  :value="item.coid"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="专业" prop="spid">
             <el-select v-model="form.spid">
               <el-option
                 v-for="item in specialitysOption"
                 :key = "item.spid"
                 :label = "item.spname"
                 :value="item.spid"
               >
               </el-option>
             </el-select>
            </el-form-item>
          </div></el-col>
        </el-row>

        <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">
          <el-form-item label="企业"  prop="enid">
            <el-select v-model="form.enid">
              <el-option
                v-for="item in enterprisesOption"
                :key="item.enid"
                :label="item.enname"
                :value="item.enid"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        </el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">
          <el-form-item label="学号" prop="snum">
            <el-input v-model="form.snum" placeholder="请输入学号" />
          </el-form-item>
        </div></el-col>
        </el-row>


        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="姓名" prop="sname">
              <el-input v-model="form.sname" placeholder="请输入姓名" />
            </el-form-item>
          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" placeholder="请输入年龄" />
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="电话" prop="tel">
              <el-input v-model="form.tel" placeholder="请输入电话" />
            </el-form-item>
          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="微信" prop="weixin">
              <el-input v-model="form.weixin" placeholder="请输入微信" />
            </el-form-item>
          </div></el-col>
        </el-row>   <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">
          <el-form-item label="QQ" prop="qq">
            <el-input v-model="form.qq" placeholder="请输入qq" />
          </el-form-item>
        </div>
        </el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">
          <el-form-item label="学历" prop="education">
            <el-input v-model="form.education" placeholder="请输入学历" />
          </el-form-item>
        </div></el-col>
      </el-row>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="籍贯" prop="nativeplace">
              <el-input v-model="form.nativeplace" type="input" placeholder="请输入内容" />
            </el-form-item>
          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="民族" prop="nation">
              <el-input v-model="form.nation" placeholder="请输入民族" />
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="出生日期" prop="birthday">
              <el-date-picker v-model="form.birthday" placeholder="请输入出生日期" />
            </el-form-item>
          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="入学时间" prop="intime">
              <el-date-picker v-model="form.intime" placeholder="请输入入学时间" />
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">

            <el-form-item label="毕业时间" prop="outtime">
              <el-date-picker v-model="form.outtime" placeholder="请输入毕业时间" />
            </el-form-item>

          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="就业时间"  prop="etime">
              <el-date-picker v-model="form.etime" clearable placeholder="请输入就业时间" />
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><div class="grid-content bg-purple">
            <el-form-item label="就业薪资" prop="money">
              <el-input v-model="form.money" placeholder="请输入就业薪资" />
            </el-form-item>

          </div>
          </el-col>
          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="就业状态" prop="stat">

              <el-select v-model="form.stat" placeholder="请输入状态、0已就业 1未就业" >
                  <el-option label="未就业" value="1"  >未就业</el-option>
                   <el-option label="已就业" value="0" >已就业</el-option>
              </el-select>
            </el-form-item>
          </div>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="12"><div class="grid-content bg-purple-light">
            <el-form-item label="性别" prop="stat">

              <el-select v-model="form.sex" placeholder="请输入状态、0男 1女" >
                <el-option label="男" value="男"  >男</el-option>
                <el-option label="女" value="女" >女</el-option>
              </el-select>
            </el-form-item>
          </div>
          </el-col>

        </el-row>












      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudentemployment, getStudentemployment, delStudentemployment, addStudentemployment, updateStudentemployment } from "@/api/studentemployment/studentemployment";
import { getProvinces } from "@/api/province/province";
import { getProvinceCitys } from "@/api/city/city";
import {getColleges} from "@/api/college/college"
import {getCollegeSpecialitys} from "@/api/speciality/speciality"
import {getAllEnterprise} from "@/api/enterprise/enterprise"

export default {
  name: "Studentemployment",
  data() {
    return {
      //获取企业数组
      enterprisesOption:[],
      //获取省会数组
      provincesOption:[],
      citysOption:[],
      collegesOption:[],
      specialitysOption:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就业管理表格数据
      studentemploymentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cityid: null,
        spid: null,
        enid: null,
        sname: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cityid: [
          { required: true, message: "城市不能为空", trigger: "blur" }
        ],
        spid: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ],
       /* enid: [
          { required: true, message: "企业不能为空", trigger: "blur" }
        ],*/
        snum: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        sname: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" }
        ],
        tel: [
          { required: true, message: "电话不能为空", trigger: "blur" }
        ],
        education: [
          { required: true, message: "学历不能为空", trigger: "blur" }
        ],
        nativeplace: [
          { required: true, message: "籍贯不能为空", trigger: "blur" }
        ],
        nation: [
          { required: true, message: "民族不能为空", trigger: "blur" }
        ],
        birthday: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        intime: [
          { required: true, message: "入学时间不能为空", trigger: "blur" }
        ],
        outtime: [
          { required: true, message: "毕业时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getProvince()
    this.getAllColleges()
    this.getEnterprises()
  },
  methods: {

    //获取所有的企业
    getEnterprises(){
      getAllEnterprise().then(response=>{
        this.enterprisesOption = response.data
      })
    },

    //获取所有的学院
    getAllColleges() {
      getColleges().then((response=>{
        this.collegesOption = response.data
      }))
    },
    //获取学院下的专业
    getCollegeAllSpeciality(){
        getCollegeSpecialitys(this.form.coid).then((response=>{
          console.log(response.data)
          this.specialitysOption = response.data
        }))
    },

    //获取省份下的城市信息
    getProvinceCity(){
      console.log(this.form.proid)
      getProvinceCitys(this.form.proid).then((response=>{
        console.log(response.data)
        this.citysOption = response.data
      }))
    },

    //查询所有省会信息
    getProvince(){
      getProvinces().then((response=>{
        this.provincesOption = response.data
      }))

    },

    /** 查询就业管理列表 */
    getList() {
      this.loading = true;
      listStudentemployment(this.queryParams).then(response => {
        this.studentemploymentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sid: null,
        cityid: null,
        spid: null,
        enid: null,
        snum: null,
        sname: null,
        sex: null,
        age: null,
        tel: null,
        weixin: null,
        qq: null,
        education: null,
        nativeplace: null,
        nation: null,
        birthday: null,
        intime: null,
        outtime: null,
        etime: null,
        money: null,
        stat: null,
        createtime: null,
        modifytime: null,
        deleted: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就业管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sid = row.sid || this.ids
      getStudentemployment(sid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就业管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sid != null) {
            updateStudentemployment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentemployment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sids = row.sid || this.ids;
      this.$modal.confirm('是否确认删除就业管理编号为"' + sids + '"的数据项？').then(function() {
        return delStudentemployment(sids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('studentemployment/studentemployment/export', {
        ...this.queryParams
      }, `studentemployment_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
